/*
使用uexXmlHttpMgr接口封装AJAX跨域请求

Q.AJAX.get('http://www.baidu.com',function(res){
	alert(res);
},function(){
	alert('请求出错'); 
});
     
//POST的第2个参数为需要post的数据
AJAX.post('http://m.baidu.com',{
	'word':'test',
	'word2':'qq360811363'
},function(res){
	alert(res);
},function(){
	alert('请求出错'); 
});
	
*/
~function () {
	Q.AJAX = {
		callBack : {},index : 1,
		get : function(url,succCall,errCall,timeout){
			var id = this.index++;
			this.callBack[id] = [succCall,errCall];
			uexXmlHttpMgr.open(id,'get',url,(timeout||0));
			this._send(id);
		},
		post : function(url,data,succCall,errCall,timeout){
			var id = this.index++;
			this.callBack[id] = [succCall,errCall];
			uexXmlHttpMgr.open(id,'post',url,(timeout||0));
			if(data){
				for(var k in data){
					uexXmlHttpMgr.setPostData(id,0,k,data[k]);
				}
			}
			this._send(id);
		},
		_send : function(id){
			uexXmlHttpMgr.onData = this.onData;
			uexXmlHttpMgr.send(id);
		},
		onData : function(inOpCode,inStatus,inResult){
			var that=Q.AJAX,callBack = that.callBack[inOpCode]||[];
			if(inStatus==-1){
				callBack[1] && callBack[1]();
				delete that.callBack[inOpCode];
			}else if(inStatus==1){
				callBack[0] && callBack[0](inResult);
				delete that.callBack[inOpCode];   
			}
		}
	};	
}(); 